home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Sample Code / AppsToGo / DTS.StyleChat / DoEvent.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-22  |  5.3 KB  |  216 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        DoEvent.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.protos.h"        /* Get the prototypes for application.            */
  27.  
  28. #ifndef __CTLHANDLER__
  29. #include "CtlHandler.h"
  30. #endif
  31.  
  32. #ifndef __DESK__
  33. #include <Desk.h>
  34. #endif
  35.  
  36. #ifndef __DISKINIT__
  37. #include <DiskInit.h>
  38. #endif
  39.  
  40. #ifndef __ERRORS__
  41. #include <Errors.h>
  42. #endif
  43.  
  44. #ifndef __MENUS__
  45. #include <Menus.h>
  46. #endif
  47.  
  48. #ifndef __TEXTEDITCONTROL__
  49. #include "TextEditControl.h"
  50. #endif
  51.  
  52. #ifndef __TEXTSERVICES__
  53. #include "TextServices.h"
  54. #endif
  55.  
  56. #ifndef __TOOLUTILS__
  57. #include <ToolUtils.h>
  58. #endif
  59.  
  60. #ifndef __UTILITIES__
  61. #include "Utilities.h"
  62. #endif
  63.  
  64.  
  65.  
  66. /*****************************************************************************/
  67.  
  68.  
  69.  
  70. extern Cursor    *gCursorPtr;    /* See the file Window.c for comments about this global. */
  71.  
  72.  
  73.  
  74. /*****************************************************************************/
  75. /*****************************************************************************/
  76.  
  77. #ifdef applec
  78. #pragma segment DoEvent
  79. #endif
  80.  
  81. /*****************************************************************************/
  82. /*****************************************************************************/
  83.  
  84.  
  85.  
  86. /* Do the right thing for an event.  Determine what kind of event it is, and
  87. ** call the appropriate routines. */
  88.  
  89. void    DoEvent(EventRecord *event)
  90. {
  91.     Point        pt;
  92.     OSErr        err;
  93.  
  94.     switch(event->what) {
  95.  
  96.         case nullEvent:
  97.             DoIdleTasks(event);
  98.             break;
  99.  
  100.         case mouseDown:
  101.             DoMouseDown(event);
  102.             break;
  103.  
  104.         case autoKey:
  105.         case keyDown:                    /* Check for menukey equivalents. */
  106.             DoKeyDown(event);
  107.             break;
  108.  
  109.         case activateEvt:
  110.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  111.             DoActivate((WindowPtr)event->message);
  112.             if (TSMTEAvailable()) TSMEvent(event);
  113.             break;
  114.  
  115.         case updateEvt:
  116.             DoUpdate((WindowPtr)event->message);
  117.             break;
  118.  
  119.         case kHighLevelEvent:
  120.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  121.             DoHighLevelEvent(event);
  122.             break;
  123.  
  124.         case osEvt:
  125.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  126.             switch ((event->message >> 24) & 0xFF) {
  127.                     /* Must logical and with 0xFF to get only low byte. */
  128.                     /* High byte of message. */
  129.  
  130.                 case mouseMovedMessage:
  131.                     DoIdleTasks(event);
  132.                     break;
  133.  
  134.                 case suspendResumeMessage:
  135.                         /* Suspend/resume is also an activate/deactivate. */
  136.                     gInBackground = !((event->message) & resumeFlag);
  137.                     CTEConvertClipboard((event->message) & convertClipboardFlag, !gInBackground);
  138.                     DoActivate(FrontWindow());
  139.                     HiliteWindows();
  140.                     break;
  141.             }
  142.             break;
  143.  
  144.         case diskEvt:
  145.             gCursorPtr = nil;            /* Force recalculation of the cursor. */
  146.             if (HiWord(event->message) != noErr) {
  147.                 SetPt(&pt, kDILeft, kDITop);
  148.                 err = DIBadMount(pt, event->message);
  149.             }
  150.             break;        /* It is not a bad idea to at least call DIBadMount
  151.                         ** in response to a diskEvt, so that the user can
  152.                         ** format a floppy. */
  153.     }
  154.  
  155.     DoCursor();
  156.     DoAdjustMenus();
  157. }
  158.  
  159.  
  160.  
  161. /*****************************************************************************/
  162.  
  163.  
  164.  
  165. /* •• Called by DTS.Lib..framework. •• */
  166.  
  167. /* This is called when a window is activated or deactivated. */
  168.  
  169. void    DoActivate(WindowPtr window)
  170. {
  171.     RgnHandle    rgn, oldClip;
  172.     Point        pt;
  173.  
  174.     NotifyCancel();
  175.  
  176.     if (IsAppWindow(window)) {
  177.  
  178.         SetPort(window);
  179.         DoCtlActivate(window);
  180.         DoDrawFrame(window, true);            /* Redraw frame for new activate state. */
  181.  
  182.         CopyRgn(((WindowPeek)window)->contRgn, rgn = NewRgn());
  183.         DiffRgn(rgn, ((WindowPeek)window)->updateRgn, rgn);
  184.             /* Don't draw any part that's already destined to draw due to an update event.
  185.             ** This prevents part of an exposed window from drawing twice, and thus avoids
  186.             ** flickering. */
  187.  
  188.         BeginContent(window);
  189.  
  190.         pt.h = pt.v = 0;
  191.         GlobalToLocal(&pt);
  192.         OffsetRgn(rgn, pt.h, pt.v);
  193.             /* This offset may seem wrong, since the origin may not be 0,0.  It is actually correct,
  194.             ** since at the time of the GlobalToLocal, the port's origin was set to the content origin.
  195.             ** A clearer way to look at this is in two steps:
  196.             ** 1) With the port's origin at 0,0, do a GlobalToLocal on 0,0, and then offset the new clip
  197.             **    by that amount.
  198.             ** 2) Once the port's origin is set correctly, the new clip needs to be offset again, based
  199.             **    on the origin value.  (The clipRgn travels with the origin, unlike the visRgn.)
  200.             ** The above is what automatically happens when you do the GlobalToLocal of 0,0 on the
  201.             ** correct origin.  Offsets are additive.  One step -- no muss, no fuss. */
  202.  
  203.         GetClip(oldClip = NewRgn());
  204.         SetClip(rgn);
  205.         DoDrawControls(window, true);        /* Redraw content scrollbars for new activate state. */
  206.         SetClip(oldClip);
  207.         DisposeRgn(oldClip);
  208.         DisposeRgn(rgn);
  209.  
  210.         EndContent(window);
  211.     }
  212. }
  213.  
  214.  
  215.  
  216.